/*
 * @Author: ellery
 * @Date: 2022-08-20 20:14:35
 * @LastEditTime: 2022-09-02 00:09:23
 * @LastEditors: ellery
 * @Description: vuex模块持久化,调用方式请阅读md
 * @FilePath: \vue2-eslint-model\src\store\index.js
 * Copyright (c) 2022 by ellery, All Rights Reserved.
 * 愿天堂没代码
 */
import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";
Vue.use(Vuex);

const modulesFiles = require.context("./modules", true, /\.js$/);
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, "$1");
  const value = modulesFiles(modulePath);
  modules[moduleName] = value.default;
  return modules;
}, {});
export default new Vuex.Store({
  modules,
  // plugins: [createPersistedState()],// 默认是存储到localStorage
  plugins: [
    createPersistedState({
      storage: window.sessionStorage, // 一般用临时缓存就够用了
      key: "CLIENT_PC_STORE" //  自定义的存数据的key名  要有语义化
    })
  ]
});
